package persentation.presentUniversityDean;

import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import vo.frameworkVO.FrameworkVO;
import businesslogic.frameworkBl.FrameworkController;

public class FrameworkPanel extends JPanel {
	private JTable table;
	private KuangjiaceluePanel1 kuangjiaceluePanel1;
	private FrameworkController frameworkController;
	private MyTabbedPane tabbedPane;
	private FrameworkVO frameworkVO;

	/**
	 * Create the panel.
	 */
	public FrameworkPanel(FrameworkController frameworkController) {

		this.frameworkController = frameworkController;
		kuangjiaceluePanel1 = new KuangjiaceluePanel1(frameworkController);

		setLayout(null);
		JButton btnNewButton = new JButton("\u4FEE\u6539");
		btnNewButton.setFont(new Font("微软雅黑", Font.PLAIN, 15));
		btnNewButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {

				tabbedPane.addOne("编辑框架策略", kuangjiaceluePanel1);

			}
		});
		btnNewButton.setBounds(337, 387, 103, 29);
		add(btnNewButton);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(89, 46, 594, 289);
		add(scrollPane);

		table = new JTable();
		table.setFont(new Font("微软雅黑", Font.PLAIN, 16));
		scrollPane.setViewportView(table);
		table.setModel(new DefaultTableModel(
			new Object[][] {
				{null, null, null},
				{null, null, null},
				{null, null, null},
			},
			new String[] {
				"\u6A21\u5757", "\u5B66\u5206\u4E0B\u9650", "\u5B66\u5206\u4E0A\u9650"
			}
		) {
			Class[] columnTypes = new Class[] {
				String.class, String.class, String.class
			};
			public Class getColumnClass(int columnIndex) {
				return columnTypes[columnIndex];
			}
			boolean[] columnEditables = new boolean[] {
				false, false, false
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(0).setResizable(false);
		table.getColumnModel().getColumn(1).setResizable(false);
		table.getColumnModel().getColumn(2).setResizable(false);
		fillTable();
	}

	public void setMyTabbedPane(MyTabbedPane tabbedPane) {
		this.tabbedPane = tabbedPane;
	}

	public void fillTable() {
		try {
			frameworkVO = frameworkController.find();
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
			ExceptionHandler.networkException();
		}
		DefaultTableModel tableModel = (DefaultTableModel) table.getModel();
		tableModel.setRowCount(0);

		String[] array = new String[3];
		array[0] = "通识通修模块";
		array[1] = String.valueOf(frameworkVO.getCompulsoryLow());
		array[2] = String.valueOf(frameworkVO.getCompulsoryHigh());
		/*
		 * System.out.println("tongshitongxiu"); System.out.println(array[0]);
		 * System.out.println(array[1]);
		 */

		tableModel.addRow(array);
		table.invalidate();
		table.updateUI();

		String[] array1 = new String[3];
		array1[0] = "核心模块";
		array1[1] = String.valueOf(frameworkVO.getCoreLow());
		array1[2] = String.valueOf(frameworkVO.getCoreHigh());
		/*
		 * System.out.println("核心"); System.out.println(array1[0]);
		 * System.out.println(array1[1]);
		 */
		tableModel.addRow(array1);
		table.invalidate();
		table.updateUI();

		String[] array2 = new String[3];
		array2[0] = "开放选修模块";
		array2[1] = String.valueOf(frameworkVO.getChooseLow());
		array2[2] = String.valueOf(frameworkVO.getChooseHigh());
		/*
		 * System.out.println("开放选修"); System.out.println(array2[0]);
		 * System.out.println(array2[1]);
		 */
		tableModel.addRow(array2);
		table.invalidate();
		table.updateUI();
	}
}
